home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / QuickDraw™ GX / Programming Stuff / Sample Code / Graphics Samples / Spinning Text ƒ / Spinning Text.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-10  |  5.5 KB  |  189 lines  |  [TEXT/KAHL]

  1. /*
  2.     Spinning text
  3.     
  4.     This application will create a line of text, set the text to an hsv color, rotate, and draw 
  5.     the text.
  6.     
  7.     
  8.     NOTES:
  9.     • This file requires the following files to run correctly:
  10.         "graphics shell.c", "Font library.c", "graphics debug library.c", "Transform library.c".
  11.  
  12.     • For the best printing results, print this file in "landscape".
  13.     
  14.     
  15.     ©1990-1993 Apple Computer, Inc.
  16.     All rights reserved.
  17. */
  18.  
  19. #include <Events.h>
  20. #include <Windows.h>
  21.  
  22. #include "graphics libraries.h"
  23. #include "graphics toolbox.h"
  24. #include "Font library.h"
  25. #include "graphics shell.h"
  26.  
  27. #define kNumberOfTextStringsDrawn    19
  28.  
  29. //
  30. //  Set up the title and size of the window 
  31. //
  32. Str255         gWindowTitle = "\p Spinning Text ";         
  33. Rect         gWindowQDRect  = {50, 10, 440, 440};
  34.  
  35. //
  36. //    If gDebugging = TRUE, graphics library errors and notices will be posted.  This functionality  will only work with 
  37. //    the "debugging" version of the QuickDraw GX init.  If this version of the init is not installed, nothing bad will happen, 
  38. //    but these  functions will not work. The "debugging" version of the QuickDraw GX init is approximately 700K.
  39. //
  40. Boolean        gDebugging = true;
  41.  
  42.  
  43. //
  44. //     Set  "gGiveMeValidation" to TRUE, if you will receive run-time validation.  
  45. //
  46. Boolean        gGiveMeValidation = true;
  47.  
  48.  
  49. //
  50. //    gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
  51. //    in main () within graphics shell.c.  You can determine the amount of graphics gxHeap required by using GraphicsBug.
  52. //    With  gGraphicsHeapSize set to 15k, I had 4 free blocks left in the graphics gxHeap. Sounds good to me.
  53. //
  54. long        gGraphicsHeapSize = 15;
  55.  
  56. gxShape     gTextShape;
  57. gxColor     gTextColor;
  58. short         gTotalNumberOfTextStringsDrawn;
  59. short         gDegreesToRotateText;
  60. fixed        gShapesXCoordinateCenter,gShapesYCoordinateCenter;
  61.  
  62.  
  63.  
  64. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  65.  
  66. void DoInitialization(aWindow)
  67. WindowPtr aWindow;
  68. {
  69.     gxPoint            textPostion;
  70.     gxRectangle     textShapeBounds;
  71.     
  72.     gTotalNumberOfTextStringsDrawn = 0;
  73.     gDegreesToRotateText = 20;
  74.  
  75.     //
  76.     //    Set up the starting text postion. This location will be set up when we
  77.     //    create our text gxShape.
  78.     //
  79.     textPostion.x = ff(50);
  80.     textPostion.y = ff(200);
  81.     
  82.     //
  83.     //  Create the text, and set the gxFont and size.
  84.     //
  85.     gTextShape = GXNewText(13,(unsigned char*)"QuickDraw™ GX", &textPostion);
  86.     SetShapeCommonFont(gTextShape, timesFont);
  87.     GXSetShapeTextSize(gTextShape, ff(45));
  88.  
  89.     //
  90.     //    A gxColor, to run through hsv space with... 
  91.     //
  92.     gTextColor.space                     = gxHSVSpace;
  93.     gTextColor.profile                     = nil;
  94.     gTextColor.element.hsv.hue             = 0x2700;
  95.     gTextColor.element.hsv.saturation     = 0xFFFF;
  96.     gTextColor.element.hsv.value         = 0xFFFF;
  97.  
  98.     //
  99.     //    Get the bounds of our text gxShape. We will then determine the center of the gxShape. 
  100.     //    The center of the gxShape will be used below in GXRotateShape which will enable us to rotate
  101.     //    our gxShape around it's center.
  102.     //
  103.     GXGetShapeBounds(gTextShape, 0L, &textShapeBounds);
  104.     gShapesXCoordinateCenter = textShapeBounds.left + textShapeBounds.right >> 1;
  105.     gShapesYCoordinateCenter = textShapeBounds.top + textShapeBounds.bottom >> 1;
  106.     
  107.     GXSetShapeAttributes (gTextShape, gxMapTransformShape);
  108. }
  109.  
  110.  
  111.  
  112. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  113.  
  114. void DoDraw(aWindow)
  115. WindowPtr aWindow;
  116. {
  117.     if (gTotalNumberOfTextStringsDrawn == kNumberOfTextStringsDrawn) 
  118.     {
  119.         gxMapping textShapeMap;
  120.         
  121.         //
  122.         //  The text  has been rotated 360 degrees. Let's erase the contents of the window
  123.         //    and reset the Shape's Transform. By resetting the Transform will reset the Transform
  124.         //    back to the GX default gxTransform (i.e. no rotate). 
  125.         //
  126.         //    With the call to GXRotateShape below, we have been only effecting the Shape's gxTransform 
  127.         //    instead of the Shape's geometry because we had set the gxMapTransformShape attribute above.
  128.         //
  129.         SetPort (aWindow);
  130.         EraseRect(&(aWindow)->portRect);
  131.  
  132.         GXGetTransformMapping(GXGetShapeTransform(gTextShape), &textShapeMap);
  133.         ResetMapping(&textShapeMap);
  134.     
  135.         //
  136.         //  Reverse the rotation direction
  137.         //
  138.         gDegreesToRotateText = -gDegreesToRotateText;
  139.     
  140.         gTotalNumberOfTextStringsDrawn = 0;
  141.     }
  142.     
  143.     GXSetShapeColor(gTextShape, &gTextColor);
  144.     GXDrawShape (gTextShape);
  145.  
  146.     GXRotateShape(gTextShape, ff(gDegreesToRotateText), gShapesXCoordinateCenter, gShapesYCoordinateCenter);
  147.     
  148.     gTextColor.element.hsv.hue += 0x0900;
  149.  
  150.     gTotalNumberOfTextStringsDrawn++;
  151. }
  152.  
  153.  
  154. /*------ DoDispose -------------------------------------------------------------------------------------*/
  155.  
  156. void DoDispose(aWindow)
  157. WindowPtr aWindow;
  158. {
  159.     //  
  160.     //    You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  161.     //    form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  162.     //    call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  163.     //    SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  164.     //    can turn notices on in this file by setting gDebugging = TRUE (above).
  165.     //
  166.     GXDisposeShape(gTextShape);  
  167.     GXDisposeShape(gWindowBoundsShape);  
  168.        DisposeWindow(aWindow);
  169. }
  170.     
  171.  
  172.  
  173. /*------ DoClick ---------------------------------------------------------------------------------------*/
  174.  
  175. void DoClick( orgMouseLoc, theWindow )
  176. gxPoint        orgMouseLoc;
  177. WindowPtr     theWindow;
  178. {
  179. }
  180.  
  181.  
  182. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  183.  
  184. void DoIdle(aWindow)
  185. WindowPtr aWindow;
  186. {
  187.     DoDraw(aWindow); 
  188. }
  189.